package view;

import java.awt.Color;
import java.awt.Graphics;

import model.Model;
import util.Direction;
import util.MyPosition;

public class BulletView extends ModelView {

    public BulletView(MyPosition myPosition, Model model, Direction direction) {
        super(myPosition, model);
        MyPosition tankPosition = myPosition;
        position.setHeight(10);
        position.setWidth(10);
        int x = position.getX() + tankPosition.getWidth() / 2 - position.getWidth() / 2;
        int y = position.getY() + tankPosition.getHeight() / 2 - position.getHeight() / 2;
        position.setX(x);
        position.setY(y);
        color = Color.black;
        faceDir = direction;
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        setBounds(position.getX(), position.getY(), position.getWidth(), position.getHeight());
        g.setColor(color);
        g.fillOval(0, 0, position.getWidth(), position.getHeight());
    }

    @Override
    public void setPosition(MyPosition position) {
        oldPosition = new MyPosition(this.position);
        this.position = new MyPosition(position);
        repaint();
    }

    @Override
    public void stay() {
        setPosition(oldPosition);
    }
}
